package restful.servlet;

import javax.servlet.http.*;

public class ResponderFactory {

	private final String contextPath;

	private final Rules rules = new Rules();

	public ResponderFactory(final String contextPath) {
		this.contextPath = contextPath;
	}

	public Responder makeResponder(Class verb, final HttpServletRequest request) {
		final Responder responder = rules.matches(verb, request.getRequestURI());
		if (responder != null) return responder;
		return new NotFoundResponder(contextPath);
	}

	public void rule(Responder responder, Class verb, String pattern) {
		rules.put(responder, verb, pattern);
	}
}
